package com.iqi.onigao.module.player;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;

import com.iqi.onigao.App;
import com.iqi.onigao.constant.SessionConstant;
import com.iqi.onigao.context.Bean;
import com.iqi.onigao.module.ErrorCheck;
import com.iqi.onigao.thread.ThreadExecutor;

import cn.hutool.log.Log;
import cn.hutool.log.LogFactory;
import net.IClient;
import net.Package;
import si.client.CPlayer;
import si.pod.FriendPOD;
import si.pod.GlobalBuffPOD;
import si.pod.ItemPOD;
import si.pod.ItemShowPOD;
import si.pod.LottetyPOD;
import si.pod.PlayerBaseInfoPOD;
import si.pod.PlayerPOD;
import si.pod.QuestPOD;
@Bean(PlayerBO.class)
public class PlayerBOImpl extends CPlayer implements PlayerBO {
	static final Log log = LogFactory.get(PlayerBOImpl.class);
	@Override
	public boolean loadPlayerResult(IClient session, Package p, int code, PlayerPOD player, String reconnectToken) {
		ErrorCheck.check(session, code);
		session.setAttr(SessionConstant.PLAYER, player);
		
		// 好友
		Map<Long, FriendPOD> friends = new HashMap<>();
		for (FriendPOD friendPOD : player.getFriends()) {
			friends.put(friendPOD.getId(), friendPOD);
		}
		session.setAttr(SessionConstant.FRIENDS, friends);
		
		// 当前任务
		Map<Integer, QuestPOD> quests = new HashMap<>();
		for (QuestPOD questPOD : player.getQuests()) {
			quests.put(questPOD.getCid(), questPOD);
		}
		session.setAttr(SessionConstant.QUESTS, quests);
		
		// 道具
		Map<Long, ItemPOD> items = new HashMap<>();
		for (ItemPOD item : player.getWarehouse()) {
			items.put(item.getId(), item);
		}
		session.setAttr(SessionConstant.ITEMS, items);
		
		
		ScheduledFuture<?> future = ThreadExecutor.scheduleAtFixedRate(new PlayerAI(session), App.EVENT_TIME, TimeUnit.SECONDS);
		session.setAttr(SessionConstant.FUTURE, future);
		return false;
	}

	@Override
	public boolean reloadPlayerResult(IClient session, Package p, int code, PlayerPOD player, String reconnectToken) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean disbindRoleResult(IClient session, Package p, int code) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean changeHeadIconResult(IClient session, Package p, int code) {
		// TODO Auto-generated method stub
		return false;
	}


	@Override
	public boolean getPlayerInfoResult(IClient session, Package p, int code, PlayerBaseInfoPOD baseInfo) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean sendGiftCodeResult(IClient session, Package p, int code, List<ItemShowPOD> items) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean updateBaseInfo(IClient session, Package p, PlayerBaseInfoPOD baseInfo) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean updateAttributes(IClient session, Package p, List<Integer> attributes) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean notifyFunctionTypeOpen(IClient session, Package p, int functionTypeId) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean notifyUnlockEvent(IClient session, Package p, int eventCid) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean notifyEnergyRecovery(IClient session, Package p, int energy, int nextRecoveryEnergyTime) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean changeShowSoulResult(IClient session, Package p, int code) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean updatePlayerGlobalBuff(IClient session, Package p, List<GlobalBuffPOD> globalBuffs) {
		// TODO Auto-generated method stub
		return false;
	}


	@Override
	public boolean changeDataResult(IClient session, Package p, int code, int type, PlayerBaseInfoPOD baseInfo) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean gatherSoulEnergyResult(IClient session, Package p, int code, int incomeCount) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean notifyNumAttr(IClient session, Package p, Map<Integer, Integer> numAttr) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean notifyMazeProgress(IClient session, Package p, int mazeCid, int progress) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean notifyUnLockHeadIcon(IClient session, Package p, int headIconId) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean notifyUnLockLoginBackground(IClient session, Package p, int background) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean notifyWeather(IClient session, Package p, int weatherCid) {
		// TODO Auto-generated method stub
		return false;
	}

//	@Override
//	public boolean notifyReadPoint(IClient session, Package p, int type, boolean show) {
//		// TODO Auto-generated method stub
//		return false;
//	}

	@Override
	public boolean notifyLottetys(IClient session, Package p, List<LottetyPOD> lottetys) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean notifyUpdatePlayerParams(IClient session, Package p, int paramID, int value) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean notifyEffectNotice(IClient session, Package p, int effectType, List<Integer> effectParams, int num) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean notifyReadPoint(IClient session, Package p, Map<Integer, Boolean> readPoint) {
		// TODO Auto-generated method stub
		return false;
	}

}
